﻿/*+===================================================================
File:      BossThreeDoor.cpp

Summary:   Định nghĩa các phương thức của CBossThreeDoor.
===================================================================+*/

#include "BossThreeDoor.h"

CBossThreeDoor::CBossThreeDoor(D3DXVECTOR2 pos, int id, int typeID)
	:CMoveableObject(pos, id, typeID)
{
	m_pBossThree = new CBossThree(BOSS3_POS[1], id,
		ID_BOSS_THREE);
	this->m_box = { m_pos.x - 420, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT , 0, 0};
	m_pExplosionGroup = new CExplosionGroup(m_pos, id, ID_BIG_EXPLOSION, 0.68f, ID_BIG_EXPLOSION);
	m_pSprite = m_pResourceManager->GetSprite(ID_SPRITE_BOSS_THREE_DOOR);
	m_pDieSprite = m_pResourceManager->GetSprite(ID_SPRITE_BOSS_THREE_DIE);
	m_bIsLive = false;
	m_fTimeDie = 0.0f;
}

CBossThreeDoor::~CBossThreeDoor()
{
	if (m_pBossThree)
		delete m_pBossThree;
	if (m_pExplosionGroup)
		delete m_pExplosionGroup;
	if (m_pDieSprite)
		delete m_pDieSprite;
}

void CBossThreeDoor::Update(float timeFrame)
{
	if (!m_bIsLive)
	{
		if (m_fTimeDie > 0)
		{
			m_fTimeDie -= timeFrame;
			this->Explode(timeFrame);
		}
		else if (m_fTimeDie < 0)
		{
			m_fTimeDie = 0.0f;
		}
		return;
	}
	m_pBossThree->Update(timeFrame);
	m_pSprite->Update(timeFrame);
	if (!m_pBossThree->IsLive())
	{
		m_fTimeDie = 0.5f;
		this->Kill();
	}
		
}

void CBossThreeDoor::Draw()
{
	if (!m_bIsLive && m_fTimeDie <= 0.0f)
	{
		D3DXVECTOR2 pos = CViewport::GetInstance()->TransformMatrix(this->m_pos);
		m_pDieSprite->Draw(pos);
		return;
	}
		
	D3DXVECTOR2 pos = CViewport::GetInstance()->TransformMatrix(this->m_pos);
	m_pSprite->Draw(pos);
	m_pBossThree->Draw();
}

void CBossThreeDoor::UpdateCollision(vector<CGameObject*> vecGameObjs, float timeFrame)
{
	if (!m_bIsLive)
		return;
	m_pBossThree->UpdateCollision(vecGameObjs, timeFrame);
}

void CBossThreeDoor::Born()
{
	this->m_bIsLive = true;
}

void CBossThreeDoor::Explode(float timeFrame)
{
	if (m_aPosEx.size() <= 6)
	{
		m_aPosEx.push_back(D3DXVECTOR2(m_pos.x - 67.33f, m_pos.y + 16.75f));
		m_aPosEx.push_back(D3DXVECTOR2(m_pos.x, m_pos.y + 16.75f));
		m_aPosEx.push_back(D3DXVECTOR2(m_pos.x + 67.33f, m_pos.y + 16.75f));
		m_aPosEx.push_back(D3DXVECTOR2(m_pos.x - 67.33f, m_pos.y - 16.75f));
		m_aPosEx.push_back(D3DXVECTOR2(m_pos.x, m_pos.y - 16.75f));
		m_aPosEx.push_back(D3DXVECTOR2(m_pos.x + 67.33f, m_pos.y - 16.75f));
		m_pExplosionGroup->SetArrayPos(m_aPosEx);
	}
	m_pExplosionGroup->Update(timeFrame);
}